package com.ace3l.legal.gwt.domainmodule.domainxform;

import com.ace3l.legal.gwt.domainmodule.gwt.GWTRole;
import com.ace3l.legal.gwt.domainmodule.gwt.GWTUser;
import com.ace3l.legal.backend.domain.Role;
import com.ace3l.legal.backend.domain.User;

import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;

/**
 * Created by IntelliJ IDEA.
 * User: ageer
 * Date: Jul 26, 2008
 * Time: 2:17:27 PM
 * To change this template use File | Settings | File Templates.
 */
public class RoleXForm {
    public static GWTRole toGWT(Role in) {
        GWTRole out = new GWTRole();
        out.setId(in.getId());
        out.setRole(in.getRole());
        out.setUsername(in.getUsername());
        return out;
    }

    public static Role fromGWT(GWTRole in) {
        Role out = new Role();
        out.setId(in.getId());
        out.setRole(in.getRole());
        out.setUsername(in.getUsername());
        return out;
    }

    public static HashSet<GWTRole> toGWTList(Set<Role> in, GWTUser owner) {
        Iterator<Role> it = in.iterator();
        HashSet<GWTRole> out = new HashSet<GWTRole>();
        while (it.hasNext()) {
            GWTRole a = toGWT(it.next());
            a.setUser(owner);
            out.add(a);
        }
        return out;
    }

    public static Set<Role> fromGWTList(HashSet<GWTRole> in, User owner) {
        Iterator<GWTRole> it = in.iterator();
        HashSet<Role> out = new HashSet<Role>();
        while (it.hasNext()) {
            Role a = fromGWT(it.next());
            a.setUser(owner);
            out.add(a);
        }
        return out;
    }
}
